<!DOCTYPE HTML>
<html>
<HEAD>
<meta charset="UTF-8">
<TITLE>类别列表</TITLE>
</HEAD>

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    //开启session
    session_start();
    
    //如果session为空，则退出
    if(!$_SESSION['username']){
     echo "<script>alert('登陆失败');
         history.go(-1);</script>";   
    }
include_once('../DB.php');
include_once('base-class.php');
$DB =  new DB();

//获取当前页码
if($_GET["page"]){
    $page=intval($_GET["page"]);
}else { 
    $page = 0;
}

//查询转盘信息
$res_list = $DB->query("select * from zhuangxiu");

//行数
$count = mysql_num_rows($res_list);

 //如果有数据
    if($count){
    //每页显示记录数
       $page_num = 10;
       //如果无页码参数则为第一页
        if ($page == 0) $page = 1;
        //计算开始的记录序号
        $from_record = ($page - 1) * $page_num;
        //获取符合条件的数据
        $res_list=$DB->get_all("select * from zhuangxiu order by id asc limit $from_record,$page_num");
        
        //分页函数
        $multi = multi($count, $page_num, $page, "contentList.php");
    }

//获取操作信息
$action=$_GET["action"];
//是否删除
if($action=="del")
{
    //获取ID号
    $id=intval($_GET["id"]);
    //获取当前时间

      //需要把上传的图片删除
        $res_list = $DB->get_one("select * from zhuangxiu where id= $id");
        $list  = explode("/",$res_list['icon']);
        
        $picName;
         foreach ( $list as $value){
            $picName = $value;
         }
         echo $filename;
         $filename = "../../upload/img/".$picName;
         echo "aa".$filename;
         //删除上传的图片操作
         if (file_exists($filename)) { 
            unlink($filename); 
          } 
                
        //$nowtime=date("Y/m/d H:i:s",time());
        $DB->delete("zhuangxiu","id =  {$id}");
            //$mysql->runSql("update class set status=0,edittime='$nowtime' where class_id=$class_id");    
       echo "<script>alert('操作成功！');location='contentList.php';</Script>";
       exit;    
}  
?>


<h1>类别列表</h1>
<a href="../index.php" style="text-decoration:none;">查看主页效果</a>
<a href="addContent.php" style="text-decoration:none;">添加/修改类别</a>
<table border=1 style="text-align:center;">
        <tr bgcolor="gray" style="font-weight:bold;text-align:center;">
            <td>序号</td><td>正文</td><td>类别</td><td>图标</td><td>删除</td><td>修改</td>
        </tr>
        <?php
            if($res_list)
            {                   
                $id = 0;
                foreach($res_list as $value)
                {
                   $type="";
                   switch($value[type]){
                       case 1:
                           $type = "装修前准备";
                           break;
                       case 2:
                           $type = "建材选购";
                           break;
                       case 3:
                           $type = "施工经验";
                           break;
                       default:
                           break;
                   }
                   if($id%2){
                      echo "<tr bgcolor='#999'>";
                    }else {
                      echo "<tr>";
                    }
                    echo "
                          <td>$value[id]</td>
                          <td>$value[content]</td>
                          <td>$type</td>
                          <td><img src='{$value[icon]}'width='50px' height='50px'></td>

                          <td><a href='contentList.php?action=del&id=$value[id]'>删除</a></td>
                          <td><a href='addContent.php?action=update&id=$value[id]'>修改</a></td>                                              
                          </tr>";

                    $id ++;
                }
            }
	    else
            {
			
                echo "<tr><td colspan=4>无记录</td></tr>";
            }
        ?>
    
    </table> 

        <h1> <?php
            echo $multi;
        ?>
        </h1>
  </body>
</html>
